package com.yls.except.util.exception;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ExceptionHandler;

import com.yls.except.util.GeneralResult;

/**
 * 异常处理
 *
 * @author xusheng
 * @version 1.0
 * @time 2015-7-8 上午9:41:44
 * @Description: {}
 */
public class ExceptionHandle {

    // 局部异常：即只能拦截本类发生的异常
    @ExceptionHandler(Exception.class)
    public void exception(Exception e, HttpServletRequest req, HttpServletResponse resp) {
        Logger log = Logger.getLogger(ExceptionHandle.class);
        log.error("error", e);
        List<Object> list = new ArrayList<Object>();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("e", e);
        list.add(map);
        GeneralResult.general(resp, list, 10000, 0);
    }
}
